package cz.mff.kusad5am.hb.dbsim;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;

import cz.mff.kusad5am.hb.schema.list.Hostel;
import cz.mff.kusad5am.hb.schema.roomlist.RoomType;

public class HostelsDBImitation {
	
	private static HostelsDBImitation instance;
	
	private List<Hostel> hostelsTemplates;
	private List<RoomType> roomTypeTemplates;
	
	public synchronized static HostelsDBImitation getIntance() {
		if (instance == null) {
			instance = new HostelsDBImitation();
		} 
		return instance;
	}
	
	
	public HostelsDBImitation() {
		prepareHostelsTemplates();
		prepareRoomTypeTemplates();
	}
	
	
	public synchronized List<Hostel> getListForCity(String country, String city) {
//		int count = new Random().nextInt(4);
		int count = 3;
		int num = new Random().nextInt(4);
		
		Set<Integer> selected = new HashSet<Integer>();
		int it = 0;
		while (it < count) {
			int which = new Random().nextInt(4);
			if (!selected.contains(which)) {
				selected.add(which);
				it++;
			}
		}
		
		List<Hostel> retList = new ArrayList<Hostel>();
		for (Integer i: selected) {
			Hostel hostel = hostelsTemplates.get(i);
			hostel.setCity(city);
			hostel.setCountry(country);
			retList.add(hostel);
		}
		return retList;
	}
	
	public synchronized Hostel getHostel(int hostelId) {
		return hostelsTemplates.get(hostelId);
	}
	
	public synchronized List<RoomType> getTypesOfRooms(int hostelId) {
		return roomTypeTemplates;
	}
	
	
	
	private void prepareHostelsTemplates() {
		hostelsTemplates = new ArrayList<Hostel>();
		
		Hostel hostel = new Hostel();
		hostel.setId(0);
		hostel.setCountry("Neverland");
		hostel.setCity("Nevercity");
		hostel.setName("Hostel dobre nadeje");
		hostel.setAddress("Zlatnicka 15");
		hostel.setZipCode("110 00");
		hostel.setPriceDormFrom("150");
		hostel.setPricePrivateFrom("300");
		hostelsTemplates.add(hostel);
		
		hostel = new Hostel();
		hostel.setId(1);
		hostel.setCountry("Neverland");
		hostel.setCity("Nevercity");
		hostel.setName("Hilton");
		hostel.setAddress("Na florenci 213");
		hostel.setZipCode("180 00");
		hostel.setPriceDormFrom("1234");
		hostel.setPricePrivateFrom("3333");
		hostelsTemplates.add(hostel);
		
		hostel = new Hostel();
		hostel.setId(2);
		hostel.setCountry("Neverland");
		hostel.setCity("Nevercity");
		hostel.setName("Top Hotel");
		hostel.setAddress("Parizska 987");
		hostel.setZipCode("130 00");
		hostel.setPriceDormFrom("1000");
		hostel.setPricePrivateFrom("3000");
		hostelsTemplates.add(hostel);

		hostel = new Hostel();
		hostel.setId(3);
		hostel.setCountry("Neverland");
		hostel.setCity("Nevercity");
		hostel.setName("SocHostel");
		hostel.setAddress("Potocni 11");
		hostel.setZipCode("180 00");
		hostel.setPriceDormFrom("50");
		hostel.setPricePrivateFrom("125");
		hostelsTemplates.add(hostel);
	}
	
	private void prepareRoomTypeTemplates() {
		roomTypeTemplates = new ArrayList<RoomType>();
		
		RoomType type = new RoomType();
		type.setId("0");
		type.setBedCount("1");
		type.setHasPrivateShower("true");
		type.setIsPrivate("true");
		type.setNote("jednoluzko");
		type.setPriceForNightForPerson("5000");
		roomTypeTemplates.add(type);
		
		type = new RoomType();
		type.setId("1");
		type.setBedCount("2");
		type.setHasPrivateShower("true");
		type.setIsPrivate("true");
		type.setNote("dvouluzko");
		type.setPriceForNightForPerson("3200");
		roomTypeTemplates.add(type);
		
		type = new RoomType();
		type.setId("2");
		type.setBedCount("6");
		type.setHasPrivateShower("false");
		type.setIsPrivate("false");
		type.setNote("sestiluzko");
		type.setPriceForNightForPerson("1000");
		roomTypeTemplates.add(type);
	}
	
	
}



